#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "data_struct.h"

/********************single list**********************************/
s_list *s_list_create(void)
{
	s_list *tmp_list;
	tmp_list = (s_list *)malloc(sizeof(s_list));
	if(NULL == tmp_list)
	{
		printf("no mem to malloc.\n");
		return NULL;
	}
	tmp_list->len = 0;
	tmp_list->head = NULL;
	return tmp_list;
}


int s_list_addnode(s_list *slist,const char *data)
{
	s_list_node *p = NULL;
	s_list_node *tmp = slist->head;
	if((NULL == data) || (NULL == slist))
	{
		return 1;
	}
	p = (s_list_node *)malloc(sizeof(s_list_node));
	if(NULL == p)
	{
		printf("no mem to malloc.\n");
		return 1;
	}
	memcpy(p->data,data,MAX_SIZE);
	if(tmp == NULL)
	{
		slist->head = p;;	
		p->next = NULL;
	}
	else
	{
		while(NULL != tmp->next)
		{
			tmp = tmp->next;
		}
		tmp->next = p;
		p->next = NULL;
	}
	slist->len++;
	return 0;
}

int s_list_print(s_list *slist)
{
	s_list_node *p = slist->head;
	if(NULL == p)
	{
		printf("S_list is null\n");
		return 1;
	}
	while(p)
	{
		printf("this node is:%s\n",p->data);
		p = p->next;
	}
	return 0;
	
}

int s_list_term(s_list *slist)
{
	s_list_node *tmp,*p = slist->head;
        if(NULL == p)
        {
                printf("S_list is null\n");
                return 1;
        }
        while(p)
        {
		tmp = p;
                printf("delet->:this node is:%s\n",p->data);
                p = p->next;
		free(tmp);
		
        }
	slist->head = NULL;
	printf("S_list destory complete\n");
	return 0;
}
/********************single list**********************************/
